﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OgilvyOne.UKNow.Model;
using System.Data;
using ECCIT.Data;

namespace OgilvyOne.UKNow.DAL
{
    public class ConvertVideoDal
    {
        string tablename = "flv_Basic";
        DataTable dt = new DataTable();
        #region 获取所有视频数据 List<ConverVideoModel> GetConvertVideo()
        /// <summary>
        /// 获取所有视频数据
        /// </summary>
        /// <returns>返回list泛型数据集合</returns>
        public List<ConverVideoModel> GetConvertVideo()
        {
            string strSql = String.Format("select * from {0}", tablename);
            dt = DBHelper.ExecuteDataSet(strSql, null).Tables[0];
            return ToModel(dt);
        }
        #endregion
        #region 根据原始视频名称获取数据 List<ConverVideoModel> GetConvertVideo(string oldName)
        /// <summary>
        /// 根据原始视频名称获取数据 
        /// </summary>
        /// <param name="oldName"> string 原始视频名字</param>
        /// <returns>返回list泛型数据集合</returns>
        public List<ConverVideoModel> GetConvertVideo(string oldName)
        {
            string strSql = String.Format("select * from {0} where vConvertFlv='{1}'", tablename, oldName);
            dt = DBHelper.ExecuteDataSet(strSql, null).Tables[0];
            return ToModel(dt);
        }
        #endregion

        #region 将DataTable转换成实体类 List<ConverVideoModel> ToModel(DataTable DTable)
        /// <summary>
        /// 将DataTable转换成实体类
        /// </summary>
        /// <param name="DTable">DataTable dt</param>
        /// <returns> 返回 List泛型集合</returns>
        private  List<ConverVideoModel> ToModel(DataTable DTable)
        {
            List<ConverVideoModel> lcv=new List<ConverVideoModel>();

            if (DTable.Rows.Count > 0)
            {
                foreach (DataRow row in DTable.Rows)
                {
                    ConverVideoModel model = new ConverVideoModel();
                    model.Vid = row["vid"] != DBNull.Value ? row["vid"].ToString() : "";
                    model.VNameOld = row["vNameOld"] != DBNull.Value ? row["vNameOld"].ToString() : "";
                    model.VNamePath = row["vNamePath"] != DBNull.Value ? row["vNamePath"].ToString() : "";
                    model.VConvertOldPath = row["vConvertOldPath"] != DBNull.Value ? row["vConvertOldPath"].ToString() : "";
                    model.VCutImagePath = row["vCutImagePath"] != DBNull.Value ? row["vCutImagePath"].ToString() : "";
                    model.VConvertFlv = row["vConvertFlv"] != DBNull.Value ? row["vConvertFlv"].ToString() : "";
                    model.VCutImage = row["vCutImage"] != DBNull.Value ? row["vCutImage"].ToString() : "";
                    if (row["videoWidth"] != DBNull.Value)
                    {
                        model.VideoWidth = int.Parse(row["videoWidth"].ToString());
                    }
                    if (row["videoHeight"] != DBNull.Value)
                    {
                        model.VideoHeight = int.Parse(row["videoHeight"].ToString());
                    }
                    if (row["vCutImageWidth"] != DBNull.Value)
                    {
                        model.VCutImageWidth = int.Parse(row["vCutImageWidth"].ToString());
                    }

                    if (row["vCutImageHeight"] != DBNull.Value)
                    {
                        model.VCutImageHeight = int.Parse(row["vCutImageHeight"].ToString());
                    }
                    model.VConvertFlag = row["vConvertFlag"] != null ? row["vConvertFlag"].ToString() : "";
                    model.VConvertDelete = row["vConvertDelete"] != null ? row["vConvertDelete"].ToString() : "";
                    model.VConvertNowFlag = row["vConvertNowFlag"] != null ? row["vConvertNowFlag"].ToString() : "";
                    if (row["vAdddate"] != DBNull.Value)
                    {
                        model.VAdddate = Convert.ToDateTime(row["vAdddate"]);
                    }
                    if (row["vUpdateDate"] != DBNull.Value)
                    {
                        model.VUpdateDate = Convert.ToDateTime(row["vUpdateDate"]);
                    }
                    model.VStatus = row["vStatus"] != null ? row["vStatus"].ToString() : "";
                    model.VDes = row["vDes"] != null ? row["vDes"].ToString() : "";
                    lcv.Add(model);
                }
                return lcv;
            }
            else { return null; }
        }
        #endregion
    }
}
